package com.acc.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.acc.entity.Msg;
import com.acc.service.AuthorityService;
import com.acc.service.impl.AuthorityServiceImpl;
import com.alibaba.fastjson.JSON;
/**
 * 
 * @author 朱春阳
 *
 */
public class DeleteServlet extends HttpServlet{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		AuthorityService authorityService = new AuthorityServiceImpl();
		//获取行值中的adminName adminRole
		String adminRole = req.getParameter("adminRole");
		String adminName = req.getParameter("adminName");
		
		//判断是否删除成功
		boolean flag = authorityService.deleteAdminRole(adminName, adminRole);
		
		//存储判断的信息
		Msg msg = new Msg();
		String result = null;
		if(flag) {
			msg.setErrorMsg("删除成功");
			msg.setSuccess(true);
			result = JSON.toJSONString(msg);
		}else {
			msg.setErrorMsg("删除失败");
			msg.setSuccess(false);
			result = JSON.toJSONString(msg);
		}
		
		resp.setContentType("application/json");
		resp.getWriter().append(result);
		
	}

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(req, resp);
	}
}
